package testing;

import gamemngr.GameMngr;
import junit.framework.TestCase;
import logic.Country;
import logic.Player;
import logic.Soldier;
import logic.moves.AttackMove;
import logic.moves.ConquerMove;
import logic.moves.SettleMove;


public class AttackMoveTest extends TestCase {

	public void testMakeMove(){
		GameMngr game = new GameMngr();
		Player player1 = new Player("Player1",new GameMngr());
		Player player2 = new Player("Player2", new GameMngr());
		game.addPlayer(player1);
		game.addPlayer(player2);

		Country israel = game.getMap().getCountries().get("Israel");
		Country egypt = game.getMap().getCountries().get("Egypt");
		SettleMove settle = new SettleMove(israel, player1);
		settle.makeMove();
		settle = new SettleMove(egypt, player2);
		settle.makeMove();

		player1.placeSoldiers(israel, 10);
		player2.placeSoldiers(egypt, 6);
		
		AttackMove attack;
		do{
			attack = new AttackMove(egypt, israel);
			assertEquals(true, attack.isLegalMove());
			attack.makeMove();
			attack.printDoMove();
			System.out.println();
		}while(!attack.isBattleFinished());
		
		if(attack.isAttackLost()){
			System.out.println("player2 has lost");
		}else{
			System.out.println("player2 has won");
			ConquerMove conquerMove = new ConquerMove(attack.getDefendingCountry(), attack.getAttackingCountry(), player2);
			assertEquals(true, conquerMove.isLegalMove());
			conquerMove.makeMove();
			conquerMove.printDoMove();
		}
	}
	
	public void testIsLegalMove(){
		GameMngr game = new GameMngr();
		Player player1 = new Player("Player1", new GameMngr());
		Player player2 = new Player("Player2", new GameMngr());
		game.addPlayer(player1);
		game.addPlayer(player2);
		
		Country israel = game.getMap().getCountries().get("Israel");
		Country egypt = game.getMap().getCountries().get("Egypt");
		Country sea = game.getMap().getCountries().get("Sea");
		SettleMove settle = new SettleMove(israel, player1);
		settle.makeMove();
		settle = new SettleMove(egypt, player2);
		settle.makeMove();
		settle = new SettleMove(sea, player2);
		settle.makeMove();
		
		Soldier army1 = new Soldier(3);
		Soldier army2 = new Soldier(6);
		Soldier army3 = new Soldier(6);

		player1.placeSoldiers(israel, 3);
		player2.placeSoldiers(israel, 6);
		player1.placeSoldiers(israel, 4);
		
		AttackMove attack = new AttackMove(egypt, israel);
		assertEquals(true, attack.isLegalMove());
		attack = new AttackMove(egypt, sea);
		assertEquals(false, attack.isLegalMove());
	}
}
